<template>
  <div class="song-list w700">
    <div class="play-control" v-show="songs.length>0">
      <div class="play-all" @click="PlayAll('random')">
        <i class="iconfont iconerji"></i>
        <p>随机播放全部</p>
        <span>(共{{songs.length}}首)</span>
      </div>
      <div class="collection" v-if="!isPerson" v-show="!hideCollect">
        <i class="iconfont iconshoucang"></i> 收藏
        <span style="fontSize:12px">({{subscribedCount | playNumFormat}})</span>
      </div>
    </div>
    <van-loading v-show="!songs.length" type="circular" color="#fff" vertical>正在加载音乐列表...</van-loading>
    <ul>
      <li v-for="(song,index) in songs" class="item" :key="index" @click="selectItem(song,index)">
        <div class="content">
          <div class="index">
            <span v-if="!isRank">{{index+1}}</span>
            <span :class="getRankCls(index+1)" v-if="isRank">{{getRankText(index+1)}}</span>
          </div>
          <div class="content-detail">
            <h2 class="name">
              {{song.name}}
              <i v-if="song.vip" class="iconfont iconVIP1">&nbsp;&nbsp;</i>
            </h2>
            <p class="desc">{{getDesc(song)}}</p>
          </div>
          <div class="play">
            <i class="iconfont icondiandiandian"></i>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  props: {
    songs: {
      type: Array,
      default: []
    },
    subscribedCount: {
      type: Number,
      default: 0
    },
    hideCollect: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      rank: false
    };
  },
  components: {},
  computed: {
    ...mapGetters(["songsheettype"]),
    isRank() {
      if (this.songsheettype === "排行榜") {
        return true;
      }
    },
    isPerson() {
      if (this.songsheettype === "私人歌单") {
        return true;
      }
    }
  },
  methods: {
    getDesc(song) {
      return `${song.singer}·${song.album}`;
    },
    selectItem(item, index) {
      this.$emit("select", item, index);
    },
    PlayAll(mode) {
      this.$emit("playAll", mode);
    },
    getRankCls(index) {
      if (index <= 3) {
        // 前三名
        return `icon rank${index}`;
      } else {
        return "text";
      }
    },
    getRankText(index) {
      if (index > 3) {
        return index;
      }
    }
  }
};
</script>

<style lang="less" >
.play-control {
  .flex-nowrap-sb;
  font-size: 16px;
  padding-bottom: 20px;
  .play-all {
    .flex-row-nowrap(center);
    // border-radius: 20px;
    // padding: 5px 10px;
    // border: 1px solid #fff;
    i {
      margin-right: 6px;
    }
    p {
      font-size: 15px;
    }
    span {
      margin-left: 3px;
      color: #999;
      font-size: small;
      font-size: 12px;
      align-self: flex-end;
    }
  }
  .collection {
    background-color: @color-sub-theme;
    color: #fff;
    font-size: 15px;
    padding: 10px 20px;
    border-radius: 20px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  }
}
.song-list {
  padding: 20px 0;
  .item {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    height: 64px;

    font-size: @font-size-medium;
    .rank {
      flex: 0 0 25px;
      width: 25px;
      margin-right: 30px;
      text-align: center;
      .icon {
        display: inline-block;
        width: 25px;
        height: 24px;
        background-size: 25px 24px;
      }
      .text {
        color: @color-theme;
        font-size: @font-size-large;
      }
    }
    .content {
      .flex-row-nowrap;
      flex: 1;
      line-height: 20px;
      overflow: hidden;

      .index {
        font-size: 18px;
        margin-right: 20px;
        font-family: DINRegular;
        color: @mc;
        border-radius: 50%;
        span.icon {
          display: inline-block;
          width: 30px;
          height: 30px;
          background-size: 30px 30px;
          &.rank1 {
            .bg-imageN("r1");
          }
          &.rank2 {
            .bg-imageN("r2");
          }
          &.rank3 {
            .bg-imageN("r3");
          }
        }
      }
      .content-detail {
        flex: 1;
        width: 100%;
      }
      .name {
        .sl;
        color: @color-text;
        font-size: 15px;
        .iconVIP1 {
          color: @color-sub-theme;
          font-size: 20px;
        }
      }
      .desc {
        .sl;
        margin-top: 4px;
        color: @color-text-d;
        font-size: 13px;
      }
      .play {
        .flex-row-nowrap;
        justify-content: center;
        align-content: center;
        i {
          font-size: 20px;
        }
      }
    }
  }
}
</style>